   
<link href="{{$LAYOUT_HELPER_URL}}admin/js/jquery-ui/css/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="{{$LAYOUT_HELPER_URL}}admin/js/jquery-ui/js/jquery-ui.js"></script>
<script src="{{$LAYOUT_HELPER_URL}}admin/js/jquery.slug.js"></script>
<!--fancybox-->

	<script type="text/javascript" src="{{$LAYOUT_HELPER_URL}}admin/js/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
	<link rel="stylesheet" type="text/css" href="{{$LAYOUT_HELPER_URL}}admin/js/fancybox/jquery.fancybox-1.3.4.css" media="screen" />

    
<script type="text/javascript">
    //<![CDATA[
jQuery(document).ready(function (){
    //Datepicker
    jQuery( ".date" ).datepicker({
        showAnim        : 'slideDown',
        showButtonPanel : true,
        dateFormat      : '{{$datepickerFormat.js}}'
    });
        
    jQuery("a[rel=thongke]").fancybox({
        'width' : '80%',
        'height' : '80%',
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'type': 'iframe'
	});
    jQuery("a[printBtn").click(function() {
        $('#myIframe')[0].print();
    });

    $('.check-all').click(
			function(){
				$(this).parent().parent().parent().parent().parent().find("input[type='checkbox']").attr('checked', $(this).is(':checked'));   
			}
		);
       
});
		// lay don vi
		var availableUnit = new Array();
		{{foreach from= $allUnit item=item key=k}}
		
		availableUnit[{{$k}}] = "{{$item.name}}";
		 {{/foreach}}
		                     
				$( "#unit" )
					// don't navigate away from the field on tab when selecting an item
					.bind( "keydown", function( event ) {
						if ( event.keyCode === $.ui.keyCode.TAB &&
								$( this ).data( "autocomplete" ).menu.active ) {
							event.preventDefault();
						}
					})
					.autocomplete({
						minLength: 0,
						source: function( request, response ) {
							// delegate back to autocomplete, but extract the last term
							response( $.ui.autocomplete.filter(
									availableUnit, extractLast( request.term ) ) );
						},
						focus: function() {
							// prevent value inserted on focus
							return false;
						},
					});
function input(id)
{
    jQuery('#input' + id).show();
    jQuery('#more').hide();
    	    
}
function output(id)
{
    jQuery('#output' + id).show();
    jQuery('#more').hide();
}
function showMenu() {
    $("#unit").autocomplete( "search" , '' );
}
</script>
            <h2>Quản lý sản phẩm</h2>
            
             <!-- End .shortcut-buttons-set -->
            
            <div class="clear"></div> <!-- End .clear -->
           
            
            
            <div class="content-box"><!-- Start Content Box -->
                
                <div class="content-box-header">
                    
                    <div style="float:left;">
                   </div>     
                   <div style="float:right;padding-right:20px;padding-top:5px;">
                        <form class="search" name="search" method="post" action="{{$APP_BASE_URL}}product/admin/manage-product">
                            Tên sản phẩm<input class="text-input small-input" type="text" name="condition[keyword]" id="keyword" value="{{$condition.keyword}}"/>
                            
                            <input class="button" type="submit" value="Tìm" />
                        </form>
                        
                   </div>
                    
                </div> <!-- End .content-box-header -->
                
                <div class="content-box-content">
                    
                    <div class="tab-content default-tab" id="tab1"> <!-- This is the target div. id must match the href of this div's tab -->
                        
                       
                       
                        <!-- MESSAGE HERE -->
                        {{if $allProduct|@count <= 0}}
                        <div class="notification information png_bg">
                            <a href="#" class="close"><img src="{{$LAYOUT_HELPER_URL}}admin/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a>
                            <div>
                                {{l}}Không có sản phẩm với điều kiện trên .{{/l}} &nbsp;&nbsp;&nbsp;&nbsp; <a href="{{$APP_BASE_URL}}product/admin/new-product/name/{{$condition.keyword}}" class="button" >Tạo mới SP</a>
                            </div>
                        </div>
                        {{/if}}
                        
                        {{if $productMessage|@count > 0 && $productMessage.success == true}}
                        <div class="notification success png_bg">
                            <a href="#" class="close"><img src="{{$LAYOUT_HELPER_URL}}admin/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a>
                            <div>
                                {{$productMessage.message}}
                            </div>
                        </div>
                        {{/if}}
                        
                        {{if $productMessage|@count > 0 && $productMessage.success == false}}
                        <div class="notification error png_bg">
                            <a href="#" class="close"><img src="{{$LAYOUT_HELPER_URL}}admin/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a>
                            <div>
                                {{$productMessage.message}}
                            </div>
                        </div>
                        {{/if}}
                        
                        <!-- END MESSAGE -->
                        
                        
                        
                        
                        {{if $allProduct|@count > 0}}
                        <table>
                            <thead>
                                <tr>
                                   <th width="3%"><input class="check-all" type="checkbox" /></th>
                                   <th width="20%">Tên sản phẩm</th>
                                   <th width="18%">Nhà sản xuất</th>
                                   <th width="12%" style="text-align: right;">Tồn kho</th>
                                    <th width="12%">Đơn vị</th>
                                    <th width="12%">Ngày tạo</th>
                                    <th width="12%">Thống kê</th>
                                   
                                   <th width="12%">Nhập/Xuất</th>
                                   <th width="11%">Sửa/Xóa</th>
                                </tr>
                                
                            </thead>
                         
                         
                            <tbody>
                            
                            {{foreach from=$allProduct item=item name=product}}
                                <tr>
                                    <table>
                                        <tr>
		                                	<td width="3%"><input type="checkbox" value="{{$item.product_id}}" name="allProduct"/></td>
		                                    <td width="20%">{{$item.title}}</td>
		                                    <td width="15%">{{$item.provider}}</td>
		                                    <td width="10%" style="text-align: right;">{{$item.store|@number_format:0:'.':' '}}</td>
		                                    <td width="10%">{{$item.unit_name}}</td>
		                                    <td width="15%">{{$item.created_date}}</td>
		                                    <td width="8%">
		                                         <a href="{{$APP_BASE_URL}}product/admin/select/id/{{$item.product_id}}" title="Thống Kê Sản Phẩm" rel="thongke"  ><img src="{{$LAYOUT_HELPER_URL}}admin/images/icons/tk.png" alt="Thong ke" title="Thống kê"/></a>
		                                    </td>
		                                    <td width="10%">
		                                    {{if $fullPermisison}}
		                                         <a href="javascript:input({{$item.product_id}});" title="Nhập hàng"><img src="{{$LAYOUT_HELPER_URL}}admin/images/icons/plus.png"  alt="Nhap" title="Nhập hàng"/></a>
		                                          <a href="javascript:output({{$item.product_id}});" title="Xuất hàng"><img src="{{$LAYOUT_HELPER_URL}}admin/images/icons/minus.png"  alt="Xuat"  title="Xuất hàng"/></a>
		                                         {{else}}
		                                         --
		                                         {{/if}}
		                                    </td>
		                                    <td width="10%">
		                                         {{if $fullPermisison}}
		                                    	 <a href="{{$APP_BASE_URL}}product/admin/edit-product/id/{{$item.product_id}}" title="Chỉnh sửa sản phẩm"><img src="{{$LAYOUT_HELPER_URL}}admin/images/icons/pencil.png"  alt="Edit Product" /></a>
		                                         <a href="javascript:deleteAProduct({{$item.product_id}})" title="Xóa sản phẩm"><img src="{{$LAYOUT_HELPER_URL}}admin/images/icons/cross.png"  alt="Delete" /></a>
		                                         {{else}}
		                                         --
		                                         {{/if}}
		                                    </td>
                                           </tr>
                                           
                                           <tr id="input{{$item.product_id}}" style="display: none;">
                                            <td colspan="9">
                                            	<form method="POST" name="sortForm">
	                                                <label style="min-width: 80px;">Ngày nhập:</label> <input type="text" class="date" name="input[created_date]" value="{{$date}}" style="float: left; width: 150px;margin-right: 10px;" />
	                                                <label style="min-width: 80px;">Giá nhập:</label> <input type="text" name="input[input_price]" value="{{$item.input_price}}" style="float: left; width: 150px;margin-right: 10px;"/>
	                                                <label style="min-width: 80px;">Số lượng:</label> <input type="text" name="input[soluong]"  style="float: left; width: 150px;margin-right: 10px;"/> ({{$item.unit_name}}) 
	                                                <br style="clear: both;"/>
	                                                <label style="min-width: 80px;">Ghi Chú:</label> <input type="text" name="input[ghichu]"  style="float: left; width: 400px;margin-right: 10px;"/>
	                                                <input type="hidden" name="isInput" value="1">
	                                                <input type="hidden" name="input[product_id]" value="{{$item.product_id}}">
	                                                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input class="button submit" type="button" value="Lưu" />
                                           		</form>
                                           </td>
                                           </tr>
                                           <tr>
                                           </tr>
                                           
                                           <tr id="output{{$item.product_id}}" style="display: none;">
                                            <td colspan="9">
                                            	<form method="POST" name="sortForm">
	                                                <label style="min-width: 80px;">Ngày xuất:</label> <input type="text" class="date" name="input[created_date]" value="{{$date}}" style="float: left; width: 150px;margin-right: 10px;" />
	                                                <label style="min-width: 80px;">Giá bán:</label> <input type="text" name="input[sale_price]" value="{{$item.sale_price}}" style="float: left; width: 150px;margin-right: 10px;" />
	                                                <label style="min-width: 80px;">Số lượng:</label> <input type="text" name="input[soluong]" style="float: left; width: 150px;margin-right: 10px;" /> ({{$item.unit_name}}) 
	                                                <br style="clear: both;"/>
	                                                <label style="min-width: 80px;">Ghi Chú:</label> <input type="text" name="input[ghichu]"  style="float: left; width:400px;margin-right: 10px;"/>
	                                                <input type="hidden" name="isInput" value="0">
	                                                <input type="hidden" name="input[product_id]" value="{{$item.product_id}}">
	                                                &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
	                                                <input class="button submit" type="button" value="Lưu" />
	                                             </form>
                                            </td>
                                           </tr>
<!--                                           <tr id="more">-->
<!--                                           </tr>-->
                                           <tr></tr>
                                    
                                    
                                    
                                    <!-- END 1 COL -->
                                </tr>
                            {{/foreach}}    
                                
                            
                            </tbody>
                            
                            
                        </table>
<!--                        <input class="button submit" type="button" value="Save" />-->
                        
                        <br/>
                        <!-- CHOOSE ACTION -->
                        {{p name=edit_product module=product}}
                        <div class="bulk-actions align-left" style="float: left;padding-top: 14px;">
                            <select id="action">
                                <option value=";">Chọn tác vụ</option>
                                {{p name=delete_product module=product}}
                                <option value="deleteProduct();">Xóa</option>
                                {{/p}}
                            </select>
                            <a class="button" href="javascript:applySelected();">Chấp nhận</a>
                        </div>
                        {{/p}}
                        
                        <div class="bulk-actions align-left" style="float: left;padding-top: 10px; padding-left:30px;">
                            <form class="search" name="search" method="post" action="{{$APP_BASE_URL}}product/admin/manage-product">
                                Hiển thị #
                                <select name="displayNum" onchange="this.parentNode.submit();" style="clear: both;">
                                    <option value="5" {{if $displayNum == 5}} selected="selected" {{/if}}>5</option>
                                    <option value="10" {{if $displayNum == 10}} selected="selected" {{/if}}>10</option>
                                    <option value="20" {{if $displayNum == 20}} selected="selected" {{/if}}>20</option>
                                    <option value="50" {{if $displayNum == 50}} selected="selected" {{/if}}>50</option>
                                    <option value="100" {{if $displayNum == 100}} selected="selected" {{/if}}>100</option>
                                    <option value="1000000000" {{if $displayNum >= 1000000000}} selected="selected" {{/if}}>All</option>
                                </select>
                            </form>
                        </div>
                        
                        <!-- PAGINATION -->
                        {{if $countAllPages > 1}}
                        <div class="pagination" style="float: right;">
                            {{if $first}}
                            <a href="?page=1" class="number" title="Trang đầu">&laquo; First</a>
                            {{/if}}
                            {{if $prevPage}}
                            <a href="?page={{$prevPage}}" class="number" title="Trang trước">&laquo;</a>
                            {{/if}}
                            
                            {{foreach from=$prevPages item=item}}
                            <a href="?page={{$item}}" class="number" title="{{$item}}">{{$item}}</a>
                            {{/foreach}}
                            
                            <a href="#" class="number current" title="{{$currentPage}}">{{$currentPage}}</a>
                            
                            {{foreach from=$nextPages item=item}}
                            <a href="?page={{$item}}" class="number" title="{{$item}}">{{$item}}</a>
                            {{/foreach}}
                            
                            {{if $nextPage}}
                            <a href="?page={{$nextPage}}" class="number" title="Trang kế tiếp">&raquo;</a>
                            {{/if}}
                            {{if $last}}
                            <a href="?page={{$countAllPages}}" class="number" title="Trang cuối">Last &raquo;</a>
                            {{/if}}
                        </div> <!-- End .pagination -->
                        {{/if}}
                    {{/if}}    
                        
                        <div class="clear"></div>
                    </div> <!-- End #tab1 -->
                    
                    
                </div> <!-- End .content-box-content -->
                
            </div> <!-- End .content-box -->
            
            
            <div class="clear"></div>
            
<script language="javascript" type="text/javascript">
$(document).ready(function(){
    document.getElementById('keyword').select();
    document.getElementById('keyword').focus();
});

function applySelected()
{
	var task = document.getElementById('action').value;
	eval(task);
}


function deleteProduct()
{
    var all = document.getElementsByName('allProduct');
    var tmp = '';
    var count = 0;
    for (var i = 0; i < all.length; i++) {
        if (all[i].checked) {
             tmp = tmp + '_' + all[i].value;
             count++;
        }
    }
    if ('' == tmp) {
        alert('Hãy chọn sản phẩm');
        return;
    } else {
    	result = confirm('Bạn có muốn xóa ' + count + ' sản phẩm?');
        if (false == result) {
            return;
        }
    }
    window.location.href = '{{$APP_BASE_URL}}product/admin/delete-product/id/' + tmp;
}


function deleteAProduct(id)
{
    result = confirm('Bạn có muốn xóa sản phẩm này?');
    if (false == result) {
        return;
    }
    window.location.href = '{{$APP_BASE_URL}}product/admin/delete-product/id/' + id;
}
</script>
